import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 * Represente un Rectangle ou un Carre a dessiner
 * @author Simon Castro
 *
 */
public class Rectangle extends AbstractForme{
	private int x1;
	private int x2;
	private int y1;
	private int y2;
	private int nseq;
	
	/**
	 * 
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 * @param nseq
	 */
	public Rectangle(int x1, int y1, int x2, int y2,int nseq){
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		this.nseq = nseq;
	}
	
	public int getX1(){
		return this.x1;
	}
	
	public int getX2(){
		return this.x2;
	}
	
	public int geY1(){
		return this.y1;
	}
	
	public int getY2(){
		return this.y2;
	}
	
	//pour les tris
	public float getAire(){
		
		//longueur * largeur
		int longueur = this.x2 - this.x1;
		int largeur = this.y2 - this.y1;
		
		return (float)(longueur * largeur);
	}

	@Override
	void draw(Graphics g, int x, int y) {
		//differencier un carre d'un rectangle
		if((x2-x1) == (y2-y1))
			g.setColor(Color.PINK);
		else
			g.setColor(Color.GREEN);
		
		g.fillRect(x, y, x2-x1, y2-y1);
		
		//Bordure rectangulaire
		g.setColor(Color.GRAY);
		((Graphics2D) g).setStroke(new BasicStroke(LARGEUR_P, DECO_P, COIN_P, 
	            LIMITE_P, PATTERN_P, DEBUT_P));
		((Graphics2D) g).drawRect(x, y, (x2-x1), (y2-y1));
	}
	
	/*
	 * (non-Javadoc)
	 * @see AbstractForme#getNseq()
	 */
	public int getNseq(){
		return this.nseq;
	}

	/*
	 * (non-Javadoc)
	 * @see AbstractForme#getCodeType()
	 */
	int getCodeType() {
		
		int code;
		
		if((x2-x1) == (y2-y1))
			//c'est un carre
			code = 1;
		else
			//c'est un rectangle
			code = 2;
		
		return code;
	}

	/*
	 * (non-Javadoc)
	 * @see AbstractForme#getDistanceMax()
	 */
	int getDistanceMax() {
		
		int distanceX = x2-x1;
		int distanceY = y2-y1;
		
		if(distanceX > distanceY)
			return distanceX;
		else
			return distanceY;
	}
}
